<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ include file="/WEB-INF/pages/share/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">  
    <title>提醒接收人列表</title>
	<link href="<%=basePath+Util.SKIN%>/css/right.css" type="text/css" rel="stylesheet">
	<script type="text/javascript" src="<%=basePath%>/js/jquery-1.7.2.js"></script>
	<script type="text/javascript" src="<%=basePath%>/js/checkbox1.js"></script>
	<script type="text/javascript" src="<%=basePath%>/js/selected.js"></script>
	<script type="text/javascript" src="<%=basePath%>/js/dbdialog/lhgdialog.min.js<%=Util.LHGDIALOG%>"></script>
	<script type="text/javascript" src="<%=basePath%>/js/oa.js"></script>
	<script type="text/javascript">
	/**/
		var api = frameElement.api, W = api.opener;
		
		$(function() {
		
		
			//setSelectedValue(); 
			setSelectedUser();
			//用户级别change事件
			//全选
			$("#all").click(function() { $('[name=ids]:checkbox').attr('checked', true); });
			//清空
			$("#empty").click(function() { 
			
				//$('[name=ids]:checkbox').attr('checked', false); 
				
				$('[name=ids]:checkbox').each(function() { 
				if($(this).attr('disabled')==null){
						this.checked = false;
					}
				});
			});
			//反选
			$("#rev").click(function() {
						$('[name=ids]:checkbox').each(function() { this.checked = !this.checked;});
			});
			
			//选择按钮
			$("#select").click(function() {
				var selected = false;
				$('[name=ids]:checkbox').each(function() {
					    if(this.checked) {
					    	selected = true; return false;
					    }
				});
			  if(!selected)	{
			  	msgDialog('请选择收件人!', 'hits.png')
			 	//dialogWithParent(W, '请选择收件人!', api, 'hits.png');
			  } else {//赋值到父窗口
			  		var addresseeIds = W.document.getElementById("adduse");
    				var addressNames = W.document.getElementById("addresseeNames");
    				
    				//选中的用户ID和名字
    				var selectedUserIds="", selectUserNames="";
    				$('[name=ids]:checkbox:checked').each(function() {
    				
    				//alert($(this).attr('disabled'));
    					if($(this).attr('disabled')==null){
	    					var userId = $(this).val();
	    					selectedUserIds += userId+ ",";
	    					selectUserNames += "<span id='"+userId+"'><font color='red'>"+$("#" + userId).val() +
	    							"</font><img src='<%=basePath%>/images/delete.gif'  name='img' onclick=javascript:deleteChooseUser('"
	    							+userId+"');>;&nbsp;</span>";
	    					$(this).attr('disabled',true);
			   				$(this).attr('checked',true);
			   			}
    				});
    				selectedUserIds = selectedUserIds.substr(0, selectedUserIds.length-1);
    				
    				//赋值到发送邮件窗口页面
    				if(addresseeIds.value && addresseeIds.value.length > 0 ) {
    					addresseeIds.value += "," + selectedUserIds;
    					addressNames.innerHTML += selectUserNames;
    				} else {
    					addresseeIds.value =  selectedUserIds;
    					addressNames.innerHTML = selectUserNames;
    				}
    				msgDialog('添加接收人成功!', 'succ.png')
    				//dialogWithParent(W, '添加收件人成功!', api, 'succ.png');
			  }
			  
			});
		});
		
		
		/**
		* 设置已经选中的用户
		*/
	 function setSelectedUser(){
	  	var v = W.document.getElementById("adduse").value;
		var ids = v.split(",");
		$('[name=ids]:checkbox').each(function() {
			for(j=0;j<ids.length;j++){
		   		if($(this).val() == ids[j]){
		   			$(this).attr('disabled',true);
		   			$(this).attr('checked',true);
		   		}
	   		}
		});
	}			
		
	
	</script>
	<script>
	$(function(){
		initSelArray('cUnit:1','cDept:1');
		var cGrade = '${cGrade}';
		var cUnit = '${cUnit}';
		var cDept = '${cDept}';
		if(null!=cGrade && cGrade!=""){
			changeGrade(cGrade);
		}
   		if(cUnit!=null && cUnit!=""){
   			changeUnit(cUnit);
   			selected('cUnit',cUnit);	//加载选中部门
   		}
   		if(cDept!=null && cDept!=""){
   			selected('cDept',cDept);	//加载选中单位
   		}
	});
	
	function changeGrade(rid){
   		var urls='<%=basePath%>/admin/sys_loadDept.action?gradeId='+rid
   		buildSelect(rid, 'cUnit',urls,'1');
   	}
   	function changeUnit(uid){
   		var rid=document.getElementById("cGrade").value;
   		var urls="<%=basePath%>/admin/sys_loadDept.action?unitId="+uid+"&gradeId="+rid;
   		buildSelect(uid, 'cDept',urls,'1');
   	}
	</script>
  </head>
  
  <body   style="background-image:none;padding-top:10px;">
      	<div class="body-box">
      	<!-- 
	    <div class="top_search" style="padding-top: 0px;width:100%">
		 -->
		<div id="container">    
		    <fieldset class="serarch_set">
			    <legend>
			  		<div class="search">查询条件</div>
			  	</legend>
			  	
			  	
			  	<form action="<%=basePath%>/oa/call_userList.action?search=1" method="post" name="userForm">
			   		<label>用户单位：</label> 
			   			<s:select list="gradeList" name="cGrade" listKey="id" listValue="gradeName" headerKey="" headerValue="请选择" theme="simple" cssStyle="width:155px;" id="cGrade" onchange="changeGrade(this.value);"></s:select>
			   			<s:select list="#{}" name="cUnit" headerKey="" headerValue="请选择" theme="simple" cssStyle="width:155px;margin-left:5px;" id="cUnit" onchange="changeUnit(this.value);"></s:select>
			   			<s:select list="#{}" name="cDept" headerKey="" headerValue="请选择" theme="simple" cssStyle="width:155px;margin-left:5px;" id="cDept"></s:select>
			   			<br/>
			   		<label>用户角色：</label> 
			   			<s:select list="roleList" name="cRole" listKey="id" listValue="roleName" headerKey="" headerValue="请选择" theme="simple" cssStyle="width:155px;"></s:select> 
			   			用户职务：<s:select list="zwList" name="cZw" listKey="id" listValue="name" headerKey="" headerValue="请选择" theme="simple" cssStyle="width:155px;margin-left:5px;"></s:select>
			   			<br/>
			   		<label>名称：</label><input type="text" name="keyWord" value="${keyWord }" size="50%"><input type="submit" value="搜索" class="link_input" name="btnsx">
			   		<input type="hidden" name="num" value="${page.num }">
			   		<input type="hidden" name="size" value="${page.size }">
			  	</form>
			</fieldset>
		
		    <table border="0" cellpadding="0" cellspacing="0" class="mytable" style="width:100%">
		    	 <tr class="fixedHeaderTr">
		    	 	<th width="10%">选择</th>
		    		<th width="10%">序列</th>
		    		<th width="15%">用户名</th>
		    		<th width="10%">职务</th>
		    		<th width="15%">真实姓名</th>
		    		<th width="15%">所属单位</th>
		    		<th width="15%">所属部门</th>
		    	</tr>
		    <s:if test="%{userList.size>0}">
		    	<s:iterator value="userList" id="user" status="x">
		    	<tr>
		    		<td align="center">
		    			<input type="checkbox" name="ids" value="${user.id }"/> 
		    			<input type="hidden" id="${user.id }" value="${user.userRealName }"/>
		    		</td>
		    		<td align="center">${x.index+1+(page.num-1)*page.size}</td>
		    		<td align="center">${user.userName}</td>
		    		<td align="center">
		    			<s:if test="%{#user.userZw==0}">局长</s:if>
		    			<s:if test="%{#user.userZw==1}">科长</s:if>
		    			<s:if test="%{#user.userZw==2}">科员</s:if>
		    		</td>
		    		<td align="center">${user.userRealName}</td>
		    		<td align="center">${user.unitName }</td>
		    		<td align="center">${user.deptName }</td>
		    	</tr>
		    	</s:iterator>
		    </s:if>
		    <s:else>
		    	<tr><td colspan="6">没有数据</td></tr>
		    </s:else>
		    </table>
		    <div class="btn_page">
		    
		    	<input type="button" id="all" value=" 全 选 " class="link_input">
				<input type="button" id="rev" value=" 反 选 " class="link_input">
				<input type="button" id="empty" value=" 清 空 " class="link_input">
				<input type="button" id="select" value=" 选 择 " class="link_input">
				<!-- 
		    	<input type="button" name="button5" value=" 全 选 " onclick="selectAll('ids');" class="link_input">
				<input type="button" name="button4" value=" 反 选 " onclick="selectReverse('ids');" class="link_input">
				<input type="button" name="button3" value=" 清 空 " onclick="clearAll('ids');" class="link_input">
				<input type="button" name="button2" value=" 选 择 " onclick="ok();" class="link_input">
				<input type="button" name="button1" value=" 确 定 " onclick="window.close();" class="link_input">
				 -->
			</div>		
			<div class="page">
				<jsp:include flush="true" page="../share/fenye.jsp">
				    <jsp:param name="url4page" value="/oa/call_userList.action?selects=${selects}&keyWord=${keyTemp}&cGrade=${cGrade }&cUnit=${cUnit }&cDept=${cDept }&cRole=${cRole }&cZw=${cZw }" />
			    </jsp:include>	    	
		    </div>
		</div>    
	</div>
	
  </body>
</html>
